/*
 * @Author: MarioGo
 * @Date: 2021-08-26 17:00:18
 * @LastEditTime: 2021-11-12 10:38:43
 * @LastEditors: MarioGo
 * @Description: Storage二次封装
 * @FilePath: /zheye/src/utils/BaseLocalStorage.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */

const config = {
  namespace: 'vue3Ts',
};
export default {
  setItem(key: string, val: string) {
    const storage = this.getStroage();
    storage[key] = val;
    window.localStorage.setItem(config.namespace, JSON.stringify(storage));
  },
  getItem(key: string) {
    return this.getStroage()[key];
  },
  getStroage() {
    return JSON.parse(window.localStorage.getItem(config.namespace) || '{}');
  },
  clearItem(key: string) {
    const storage = this.getStroage();
    delete storage[key];
    window.localStorage.setItem(config.namespace, JSON.stringify(storage));
  },
  clearAll() {
    window.localStorage.clear();
  },
};
